﻿@{
    Layout = null;
}
<!DOCTYPE html>

<html style="height:100%">
<head>
    <meta name="viewport" content="width=device-width" />
    <title>用户选择窗体</title>
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/jqueryEasyui/js")
    @Styles.Render("~/jqueryEasyui/css")
    <script src="/Scripts/jQuery.Extensions.js"></script>

    <script type="text/javascript">
        var data = $.ifdata("dialogUser");
        $(function () {
            $('#UserList').datagrid({
                url: "/adminweb/user/getUserOutRole?roleId=" + data.roleid + "&key=" + $("#userKey").searchbox("getValue"),
                singleSelect: false,
                height: $("body").height() - 90,
                checkOnSelect: true,
                selectOnCheck:true,
                onLoadSuccess: function () {
                    $('.easyui-linkbutton').linkbutton({ height: 20 });
                },
                columns: [[
                    { field:"ck", checkbox:true},
                    { title: "用户名", field: "Account", width: 130, halign: "center" },
                    { title: "管理员姓名", field: "UserName", width: 130, halign: "center" },
                    { title: "Email", field: "Email", width: 180, halign: "center" },
                    {
                        title: "状态", field: "IsDisabled", width: 50, align: "center",
                        formatter: function (value, row, index) {
                            if (value) {
                                return "开启";
                            } else {
                                return "禁用";
                            }
                        }
                    }
                ]],
                view: detailview,
                detailFormatter: function (index, row) {
                    return '<div style="padding:2px"><table class="ddv"></table></div>';
                },
                onExpandRow: function (index, row) {
                    var ddv = $(this).datagrid('getRowDetail', index).find('table.ddv');
                    ddv.datagrid({
                        url: '/adminweb/user/getAdminRolesByAdminId/' + row.UserID,
                        title: "所拥有的角色",
                        fitColumns: true,
                        singleSelect: true,
                        rownumbers: true,
                        loadMsg: '',
                        height: 'auto',
                        columns: [[
                            { field: 'RoleName', title: '角色名称', width: 100 },
                            {
                                field: 'RoleIntro', title: '说明', width: 100,
                                formatter: function (value, row, index) {
                                    if (value == "null") {
                                        return "";
                                    } else {
                                        return value;
                                    }
                                }
                            }
                        ]],
                        onResize: function () {
                            $('#UserList').datagrid('fixDetailRowHeight', index);
                        },
                        onLoadSuccess: function () {
                            setTimeout(function () {
                                $('#UserList').datagrid('fixDetailRowHeight', index);
                            }, 0);
                        }
                    });
                    $('#UserList').datagrid('fixDetailRowHeight', index);
                }
            });  // end datagrid

        });

        var search = function (val) {
            $('#UserList').datagrid({
                url: "/adminweb/user/getUserOutRole?key=" + $("#userKey").searchbox("getValue")
            });
        }
        var addUser = function ()
        {
            //获取
            $.messager.confirm("系统提示", "确定要添加此用户吗？", function (r) {
                if (r) {
                    var ud = $("#UserList").datagrid("getSelections");
                    var ar = [];
                    for (var i = 0; i < ud.length; i++) {
                        ar.push(ud[i].UserID);
                    }

                    var ifdata = $.ifdata("dialogUser");
                    if (ifdata.user != null && ifdata.user != undefined) {
                        $.post(
                            "/adminweb/role/addUser",
                            {
                                roleId: ifdata.roleid,
                                userIds: ar.join(",")
                            },
                            function (d) {
                                if (d.status =="y") {
                                    $.messager.alert("系统提示", "用户添加成功！", "info", function () {
                                        $.ifdata("dialogUser", ud);
                                        window.parent.$("#dialogUser").dialog("close");
                                    })
                                } else {
                                    $.messager.alert("系统提示", "用户添加失败！请重试或联系管理员！", "error");
                                }

                            })
                    }
                    
                }
            });
        }


    </script>
</head>
<body style="height:100%">
    <div>
        <div style="margin-bottom: 10px;">
            <span style="margin-left: 10px;">用户名称：</span>
            <input id="userKey" class="easyui-searchbox" data-options="prompt:'请输入用户名称、用户名',searcher:search" style="width: 250px" />
        </div>
    </div>
    <div>
        <table id="UserList">
        </table>
    </div>
    <div>
        <a href="javascript:void(0)" class="easyui-linkbutton" style="float:right; margin-right:30px; margin-top:10px;" onclick="addUser()" data-options="plain:true,iconCls:'icon-save'">确定选择</a>
    </div>
</body>
</html>
